#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e6+10;
typedef long long LL;
LL a[N];
LL n,m;
LL calc(LL x)
{
    LL sum=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]>x)sum+=a[i]-x;
    }
    return sum;
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    int left=0;LL right=a[n];
    while(left<right)
    {
        int mid=(left+right+1)/2;
        if(calc(mid)>=m)left=mid;
        else right=mid-1;
    }
    cout<<left;
    return 0;
}
